package com.CMUBiS.Depreciated;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;

import com.CMUBiS.Data.GlobalVars;

/**
 * This servlet displays "Hello World!", and gives us an example of some simple code structure to follow.
 * Make sure you comment your code well so that others can easily use it.
 * <p>
 * This class could also be used to place common functions/styles as this
 * class will not be used for any benchmarking.
 * 
 * @author Andy Turner
 * @version 0.1
 * @since 0.1
 * @date 04/04/2011
 * 
 */
@WebServlet(name="HelloWorld", urlPatterns={"/helloworld", "/anotherurl"})
public class HelloWorld extends HttpServlet {
	
	/*
	 * Some variables may need descriptions as to what they do; this isn't really one of them.
	 * However, note the lowercase first letter, and uppercase for words after. We're not going
	 * for hardcore Hungarian notation here, but let's try to keep variable names standard(ish)
	 * and self-explanatory(ish)
	 */
	private static final long serialVersionUID = 6475041003028438743L;
	
	// This is never used, but please don't delete (for some reason)
	private int fakeVariable = 0;
	
	/**
	 * This is the standard doGet for servlets. This returns the page the user is going to see.
	 * We don't need to do param and returns for these but I'll do it just as an example.
	 * @param	request	The request being sent to the servlet from the user. It may include juicy info!
	 * @param	response	The response that we are going to send back to the user
	 * @return	void	However, res does contain info to return. Other methods may have specific return types
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// Do as much stuff before going to HTML4 or 5 specific as possible
		// do auth
		if(GlobalVars.debug){
			System.out.println("HelloWorld (doGet): we're doing stuff before calling HTML4 or HTML5 specific stuff");
		}
			
		// Do HTML4 or 5 depending on the global variables
		if(GlobalVars.isHTML4)
			createHTML4(response);
		else
			createHTML5(response);
		
		// if auto == true, return ret
		// else return error
		
  }
	
	public HttpServletResponse createHTML4(HttpServletResponse res){
		try{
			if(GlobalVars.debug){
				System.out.println("HelloWorld (doGet): Getting HTML4 document");
			}
			
			// Set the return type
			res.setContentType("text/html");
			
			// We are using PrintWriter to be friendly to the international community. PrintWrite auto-converts coding
			PrintWriter out = res.getWriter();
	
			// Create the response for the user
			out.println("<HTML>");
			out.println("<HEAD><TITLE>Hello World from HTML4</TITLE></HEAD>");
			out.println("<BODY>");
			out.println("Hello World!  from HTML4");
			out.println("</BODY></HTML>");
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return res;
	}
	
	public HttpServletResponse createHTML5(HttpServletResponse res){
		try{
			if(GlobalVars.debug){
				System.out.println("HelloWorld (doGet): Getting HTML5 document");
			}
			
			// TODO: not really HTML5
			// Set the return type
			res.setContentType("text/html");
			
			// We are using PrintWriter to be friendly to the international community. PrintWrite auto-converts coding
			PrintWriter out = res.getWriter();
	
			// Create the response for the user
			out.println("Hello World from HTML5");
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return res;
	}
}
